package demo1;

import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;

public class localtime {


    //1.创建一个日期类对象
    public static void main1(String[] args) {
        //LocalDateTime time1=new LocalDataTime();
        LocalDateTime time1=LocalDateTime.of(2025,9,25,21,20);
        System.out.println("of有参："+time1);

        LocalDateTime time2=LocalDateTime.now();
        System.out.println("now无参："+time2);

        LocalDateTime parsed=LocalDateTime.parse("2024-05-12T10:30:30");
        System.out.println(parsed);
    }



    //2.通过对象获取年月日时分秒
    public static void main2(String[] args) {
        LocalDateTime time1=LocalDateTime.now();

        int year=time1.getYear();
        System.out.println ("年:"+year);

        int month= time1.getMonthValue();
        System.out.println ("月:"+month);

        int day=time1.getDayOfMonth();
       System.out.println ("日:"+day);

       int hour=time1.getHour();
        System.out.println ("时:"+hour);

        int minute=time1.getMinute();
        System.out.println ("分:"+minute);

        int second=time1.getSecond();
        System.out.println ("秒:"+second);



    }


    //3.
    public static void main(String[] args) {

        String time="2027-10-01 10:30:30";

        DateTimeFormatter datatimeformatter=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        LocalDateTime time1=LocalDateTime.parse(time,datatimeformatter);

        System.out.println("当前日期为："+time1);



    }

}
